package com.simple.http.api;

import android.content.Context;

import java.util.HashMap;

public class HttpHeader {
    private static HashMap<String, String> header;
    private static Context context;

    public static void initHeader(Context context) {
        HttpHeader.context = context.getApplicationContext();

        header = new HashMap<>();
        header.put("Content-type", "application/json;charset=utf-8");
    }

    /**
     * 修改
     *
     * @param kValues
     */
    public static void changeHeader(String... kValues) {
        if (kValues == null || kValues.length == 0) {
            return;
        }
        int len = kValues.length;
        if (len % 2 == 1) {
            len -= 1;
        }
        for (int i = 0; i < len; i++) {
            String k = kValues[i];
            i++;
            String v = kValues[i];
            if (v == null || k == null) {
                continue;
            }
            header.put(k, v);
        }
    }

    public static HashMap<String,String> getHeader() {
        if (header == null) {
            HttpHeader.initHeader(context);
        }
        return header;
    }

}
